package com.heima.user.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.ApUser;
import com.heima.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 主要用来被远程调用
 */
@RestController
@RequestMapping("/api/v1/user")
public class ApUserController {

    @Autowired
    private IUserService userService;
    /**
     * 根据用户id去查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<ApUser> findUserById(@PathVariable Integer id){
        ApUser apUser = userService.getById(id);
        if(apUser==null){
            return  ResponseResult.errorResult(AppHttpCodeEnum.AP_USER_DATA_NOT_EXIST);
        }
        return ResponseResult.okResult(apUser);
    }
}
